// generateRouter.js
const chalk = require('chalk')
const fs = require('fs')
const log = message => console.log(chalk.green(`${message}`))
//目标js
const routerJspath = './src/router/index.js'

function updateRouterJS(name,path){
  let data = fs.readFileSync(routerJspath)
  log('读取index.js')
  let content = data.toString()
  let newImport = `import `+name+` from '`+path+`'
//_@import_end`
  content = content.replace(`//_@import_end`,newImport)
  let newRouter = `      {
        path : '/`+name+`',
        name : '`+name+`',
        component : `+name+`,
      }, 
//_@router_end`
  content = content.replace(`//_@router_end`,newRouter)
  return content
}
module.exports = { updateRouterJS }
